package com.vortex.cloud.sample.controller;

import com.vortex.cloud.sample.domain.StatsInfo;
import com.vortex.cloud.sample.dto.StatsInfoDTO;
import com.vortex.cloud.sample.dto.StatsInfoQueryDTO;
import com.vortex.cloud.sample.dto.TaskUserQueryDTO;
import com.vortex.cloud.sample.service.StatsInfoService;
import com.vortex.cloud.sample.vo.StatsInfoVo;
import com.vortex.cloud.sample.vo.TaskUserVo;
import com.vortex.cloud.vfs.lite.base.dto.DataStoreDTO;
import com.vortex.cloud.vfs.lite.base.dto.RestResultDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Set;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-10-21 周四
 * @time 14:03
 * @description
 */
@Tag(name = "数据统计信息管理")
@Validated
@CrossOrigin
@RestController
@RequestMapping("cloud/sample/api/v101/stats")
public class StatsInfoController {

    @Resource
    private StatsInfoService statsInfoService;

    @Operation(summary = "保存")
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public RestResultDTO<String> save(@Parameter(description = "用户ID") @RequestHeader String tenantId,
                                      @Validated @RequestBody(required = true) StatsInfoDTO dto) {
        return statsInfoService.save(tenantId, dto) > 0 ? RestResultDTO.newSuccess("新增成功") : RestResultDTO.newFail("新增失败");
    }

    @Operation(summary = "修改")
    @PostMapping(value = "/update")
    public RestResultDTO<String> update(@Parameter(description = "用户ID") @RequestHeader String tenantId,
                                        @Validated @RequestBody(required = false) StatsInfoDTO dto) {
        return statsInfoService.update(tenantId, dto) > 0 ? RestResultDTO.newSuccess("修改成功") : RestResultDTO.newFail("修改失败");
    }

    @Operation(summary = "删除")
    @DeleteMapping(value = "/delete")
    public RestResultDTO<String> delete(@RequestParam Set<String> ids) {
        return statsInfoService.delete(ids) > 0 ? RestResultDTO.newSuccess("删除成功") : RestResultDTO.newFail("删除失败");
    }

//    @Operation(summary = "分页查询")
//    @PostMapping(value = "/page")
//    public RestResultDTO<DataStoreDTO<StatsInfoVo>> page(@ParameterObject @PageableDefault(sort = "createTime", direction = Sort.Direction.DESC) Pageable pageable,
//                                                         @Parameter(description = "租户ID") @RequestHeader String tenantId,
//                                                         @ParameterObject StatsInfoQueryDTO dto) {
//        return RestResultDTO.newSuccess(statsInfoService.page(tenantId, pageable, dto));
//    }

    @Operation(summary = "分页查询")
    @PostMapping(value = "/page")
    public RestResultDTO<DataStoreDTO<StatsInfoVo>> page(@ParameterObject @PageableDefault(sort = "createTime", direction = Sort.Direction.DESC) Pageable pageable,
                                                         @Parameter(description = "租户ID") @RequestHeader String tenantId,
                                                         @ParameterObject StatsInfoQueryDTO dto) {
        return RestResultDTO.newSuccess(statsInfoService.page(tenantId, pageable, dto));
    }


}
